package com.marketapp.domain;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

@NamedQueries({ @NamedQuery(name = "getUserByName", query = "from UserInfo userInfo where UPPER(userInfo.userName)=:userName") })
@Entity
@Table(name = "USER_INFO")
public class UserInfo {

	private int userId;
	private String userName;
	private String userPassword;
	private int enabled;
	private boolean isAdmin;
	private UserDetails userDetails;
	private Set<UserRole> userRoles;

	public UserInfo() {

	}

	public UserInfo(String userName, String userPassword, int enabled,
			boolean isAdmin, UserDetails userDetails, Set<UserRole> userRole) {
		this.userName = userName;
		this.userPassword = userPassword;
		this.enabled = enabled;
		this.isAdmin = isAdmin;
		this.userDetails = userDetails;
		this.userRoles = userRole;
	}

	@Id
	@Column(name = "USER_ID")
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	@Column(name = "USERNAME")
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	@Column(name = "PASSWORD")
	public String getUserPassword() {
		return userPassword;
	}

	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}

	@Column(name = "IS_ADMIN")
	public boolean isAdmin() {
		return isAdmin;
	}

	public void setAdmin(boolean isAdmin) {
		this.isAdmin = isAdmin;
	}

	@Column(name = "IS_ENABLED")
	public int getEnabled() {
		return enabled;
	}

	public void setEnabled(int enabled) {
		this.enabled = enabled;
	}

	@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "USER_DETAIL_ID")
	public UserDetails getUserDetails() {
		return userDetails;
	}

	public void setUserDetails(UserDetails userDetails) {
		this.userDetails = userDetails;
	}

	@OneToMany(mappedBy = "userInfo", targetEntity = UserRole.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	public Set<UserRole> getUserRoles() {
		return userRoles;
	}

	public void setUserRoles(Set<UserRole> userRoles) {
		this.userRoles = userRoles;
	}
}
